package com.smart4j.chapter.first;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * description: 第一个Servlet 用于 用于测试。。
 * @version v1.0
 * @author w
 * @date 2018年8月4日下午9:43:34
 *
 */
@WebServlet(urlPatterns={"","/hello.html","/hello"})
public class FirstServlet extends HttpServlet {
	
	private static final Logger logger = LoggerFactory.getLogger(FirstServlet.class);
	
	/**
	 * field: serialVersionUID
	 * field_type:long
	 * file_name:FirstServlet.java
	 */
	private static final long serialVersionUID = -4594857856557492619L;

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	//	response.sendRedirect("https://www.baidu.com");
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String currentTime = dateFormat.format(new Date());
		request.setAttribute("currentTime", currentTime);
		request.setAttribute("currentDate", new Date());
		logger.info(request.getRequestURL() + " request");
		request.getRequestDispatcher("WEB-INF/views/hello/hello.jsp").forward(request,response);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
}
